{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "Chapter 05\n",
    "# 用嵌套列表构造矩阵\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "# 用嵌套列表构造矩阵\n",
    "A = [[0, 5],\n",
    "     [3, 4],\n",
    "     [5, 0]]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T16:40:50.412017Z",
     "end_time": "2024-07-02T16:40:50.415999Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 5]\n",
      "[[0, 5]]\n"
     ]
    }
   ],
   "source": [
    "# 取出行向量\n",
    "print(A[0])\n",
    "print([A[0]])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T16:40:56.749989Z",
     "end_time": "2024-07-02T16:40:56.758247Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[3, 4]\n",
      "[[3, 4]]\n"
     ]
    }
   ],
   "source": [
    "print(A[1])\n",
    "print([A[1]])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T16:41:04.368605Z",
     "end_time": "2024-07-02T16:41:04.375159Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 0]\n",
      "[[5, 0]]\n"
     ]
    }
   ],
   "source": [
    "print(A[2])\n",
    "print([A[2]])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T16:41:11.623227Z",
     "end_time": "2024-07-02T16:41:11.631747Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0, 3, 5]\n",
      "[[0], [3], [5]]\n"
     ]
    }
   ],
   "source": [
    "# 取出列向量\n",
    "print([row[0] for row in A])\n",
    "print([[row[0]] for row in A])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T16:41:18.636666Z",
     "end_time": "2024-07-02T16:41:18.646944Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5, 4, 0]\n",
      "[[5], [4], [0]]\n"
     ]
    }
   ],
   "source": [
    "print([row[1] for row in A])\n",
    "print([[row[1]] for row in A])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-02T16:41:24.795612Z",
     "end_time": "2024-07-02T16:41:24.803263Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
